MockEnvironment = function(opts) {
    this.data = {};
    this.event = {};
    this.opts = opts;
    this.placeService = this.opts.placeService;
};

MockEnvironment.prototype = {
    places: function(opts) {
        this.placeService.places(opts);
    },

    signal: function(handler) {
        $(this.event).on('signal', function(event, spec) {
            handler(spec);
        });
    },

    addEvent: function(e) {
        this.opts.events.push(e);
        this.start();
    },

    start: function() {
        if (this.running) {
            return;
        }
        if (!this.opts.events.length) {
            return;
        }
        this.running = true;
        var events = this.opts.events.slice(0);
        var handle = setInterval($.proxy(function() {
            if (events.length) {
                var e = events.shift();
                $(this.event).trigger('signal', [e]);
            } else {
                clearInterval(handle);
                this.running = false;
            }
        }, this), 1);
    }
};
